package indi.walty.dl8888_dirver.ui;

import java.awt.BorderLayout;
import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import indi.walty.dl8888_dirver.Config;

public class WqFrame {
	private JTextField textWidth;
	private JTextField textHeight;
	private JButton printBtn;
	private JButton fileBtn;
	private JButton learnBtn;
	private PrintListener printListener;
	public WqFrame() {
		
	}
	
	public void show() {
		initFrame();
	}
	
	private void initFrame() {
		JFrame frame = new JFrame("Linux_DL888_Dirver");
		JPanel box = new JPanel();
		//box.setLayout(new BorderLayout());
		JPanel top = initTopPanel();
		//JPanel main = initMainPanel();
		JPanel foot = initFootPanel();
		box.add(top);
		box.add(foot);
		frame.add(box);
		frame.setSize(Config.FRAME_WIDTH,Config.FRAME_HEIGHT);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		initLisener();
		frame.setVisible(true);
	}
	
	private JPanel initTopPanel() {
		JPanel rePanel;
		rePanel = new JPanel();
		rePanel.setLayout(new GridLayout(1,5));
		fileBtn = new JButton("choose file");
		textWidth = new JTextField();
		textHeight = new JTextField();
		textWidth.setEditable(true);
		textHeight.setEditable(true);
		rePanel.add(new JLabel("width:"));
		rePanel.add(textWidth);
		rePanel.add(new JLabel("height:"));
		rePanel.add(textHeight);
		rePanel.add(fileBtn);
		return rePanel;
	}
	
	private JPanel initFootPanel() {
		JPanel repanel = new JPanel();
		repanel.setLayout(new GridLayout(1,2));
		learnBtn = new JButton("learn");
		printBtn = new JButton("print");
		repanel.add(learnBtn);
		repanel.add(printBtn);
		return repanel;
	}
	
	private void initLisener() {
		printListener = new PrintListener(textWidth,textHeight,null);
		fileBtn.addMouseListener(new ChooseFileListener(this));
		printBtn.addMouseListener(printListener);
		learnBtn.addMouseListener(new LearnListener());
	}
	
	public void setPath(String path) {
		printListener.setPath(path);
	}
}
